package org.saxion.saktiehuis.model;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Scope;

@Scope("session")
public class UserSession {

	private Map<Product, Integer> shopCart;
	private Boolean loggedIn;
	private String username;

	public UserSession() {
		shopCart = new HashMap<Product, Integer>();
		loggedIn = false;
	}

	public void addProduct(Product product, Integer amount) {
		shopCart.put(product, amount);
	}

	public void removeProduct(Integer productId) {
		shopCart.remove(productId);
	}

	public void updateProductAmount(Product product, Integer amount) {
		shopCart.put(product, amount);
	}

	public void login(String username) {
		loggedIn = true;
		this.username = username;
	}

	public void logout() {
		loggedIn = false;
		this.username = null;
	}

	public Boolean isLoggedIn() {
		return loggedIn;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public Map<Product, Integer> getContentOfCart () {
		return shopCart;
	}

	public void emptyCart() {
		shopCart.clear();
		
	}

}
